package com.zx.codegenerator.domain;

import java.util.HashSet;
import java.util.Set;

import com.zx.codegenerator.GenerateUtils;

/**
 * 表字段类型字段.
 */
public class MysqlColumnInfo {

    // private String type;
    //
    // private String field;
    //
    // private String columnName;

    private String table_catalog;

    private String table_schema;

    private String table_name;

    private String column_name;

    private String column_default;

    private String is_nullable;

    private Long ordinal_position;

    private String data_type;

    private Long character_maximum_length;

    private Long character_octet_length;

    private Long numeric_precision;

    private Long numeric_scale;

    private Long datetime_precision;

    private String character_set_name;

    private String collation_name;

    private String column_type;

    private String column_key;

    private String extra;

    private String privileges;

    private String column_comment;

    public String getField() {
        return GenerateUtils.convertCamel(column_name);
    }

    public String getColumnName() {
        return column_name;
    }

    public String getTable_catalog() {
        return table_catalog;
    }

    public void setTable_catalog(String table_catalog) {
        this.table_catalog = table_catalog;
    }

    public String getTable_schema() {
        return table_schema;
    }

    public void setTable_schema(String table_schema) {
        this.table_schema = table_schema;
    }

    public String getTable_name() {
        return table_name;
    }

    public void setTable_name(String table_name) {
        this.table_name = table_name;
    }

    public String getColumn_name() {
        return column_name;
    }

    public void setColumn_name(String column_name) {
        this.column_name = column_name;
    }

    public String getColumn_default() {
        return column_default;
    }

    public void setColumn_default(String column_default) {
        this.column_default = column_default;
    }

    public String getIs_nullable() {
        return is_nullable;
    }

    public void setIs_nullable(String is_nullable) {
        this.is_nullable = is_nullable;
    }

    public Long getOrdinal_position() {
        return ordinal_position;
    }

    public void setOrdinal_position(Long ordinal_position) {
        this.ordinal_position = ordinal_position;
    }

    public String getData_type() {
        return data_type;
    }

    public void setData_type(String data_type) {
        this.data_type = data_type;
    }

    public Long getCharacter_maximum_length() {
        return character_maximum_length;
    }

    public void setCharacter_maximum_length(Long character_maximum_length) {
        this.character_maximum_length = character_maximum_length;
    }

    public Long getCharacter_octet_length() {
        return character_octet_length;
    }

    public void setCharacter_octet_length(Long character_octet_length) {
        this.character_octet_length = character_octet_length;
    }

    public Long getNumeric_precision() {
        return numeric_precision;
    }

    public void setNumeric_precision(Long numeric_precision) {
        this.numeric_precision = numeric_precision;
    }

    public Long getNumeric_scale() {
        return numeric_scale;
    }

    public void setNumeric_scale(Long numeric_scale) {
        this.numeric_scale = numeric_scale;
    }

    public Long getDatetime_precision() {
        return datetime_precision;
    }

    public void setDatetime_precision(Long datetime_precision) {
        this.datetime_precision = datetime_precision;
    }

    public String getCharacter_set_name() {
        return character_set_name;
    }

    public void setCharacter_set_name(String character_set_name) {
        this.character_set_name = character_set_name;
    }

    public String getCollation_name() {
        return collation_name;
    }

    public void setCollation_name(String collation_name) {
        this.collation_name = collation_name;
    }

    public String getColumn_type() {
        return column_type;
    }

    public void setColumn_type(String column_type) {
        this.column_type = column_type;
    }

    public String getColumn_key() {
        return column_key;
    }

    public void setColumn_key(String column_key) {
        this.column_key = column_key;
    }

    public String getExtra() {
        return extra;
    }

    public void setExtra(String extra) {
        this.extra = extra;
    }

    public String getPrivileges() {
        return privileges;
    }

    public void setPrivileges(String privileges) {
        this.privileges = privileges;
    }

    public String getColumn_comment() {
        return column_comment != null ? column_comment.replaceAll("\n", "").replaceAll("\r", "") : "";
    }

    public void setColumn_comment(String column_comment) {
        this.column_comment = column_comment;
    }

    Set<String> getInt() {
        Set<String> intset = new HashSet<String>();
        intset.add("tinyint");
        intset.add("smallint");
        intset.add("mediumint");
        intset.add("int");
        intset.add("integer");
        intset.add("serial");
        return intset;
    }

    Set<String> getChar() {
        Set<String> intset = new HashSet<String>();
        intset.add("char");
        intset.add("varchar");
        intset.add("tinyblob");
        intset.add("tinytext");
        intset.add("blob");
        intset.add("text");
        intset.add("mediumblob");
        intset.add("mediumtext");
        intset.add("logngblob");
        intset.add("longtext");
        intset.add("varbinary");
        intset.add("binary");
        return intset;
    }

    public String getType() {// bean 对应列类型(根据db类型转换)
        data_type = data_type.toLowerCase();
        if (getInt().contains(data_type)) {
            return "Integer";
        } else if ("bigint".equals(data_type)) {
            return "Long";
        } else if (getChar().contains(data_type)) {
            return "String";
        } else if (data_type.startsWith("timestamp") || data_type.startsWith("time") || data_type.startsWith("date") || data_type.startsWith("datetime")) {
            return "Date";
        } else if ("boolean".equals(data_type) || "bit".equals(data_type)) {
            return "Boolean";
        } else if (data_type.startsWith("numeric") || data_type.startsWith("decimal")) {
            return "BigDecimal";
        } else if (data_type.startsWith("float")) {
            return "Float";
        } else if (data_type.startsWith("double")) {
            return "Double";
        }

        return "__UNKNOWN__";
    }

}
